<?php
/**
 * 商户后台--优惠券管理控制器
 * @author 孙银川
 * @date   2018.1.2
 */

namespace app\index\controller;

class Coupons extends Base{

	/**
     * 优惠券列表(已使用)
     */
	public function coupList(){
		// 商户ID
		session('shop_id',1);
		$shop_id = session('shop_id');
		$map['c.cp_use_shop'] = ['c.cp_use_shop','=',$shop_id];
		if(input('get.act') == 's'){
			$name = input('post.name');
			if($name) $map['u.nick_name'] = ['u.nick_name','like','%'.$name.'%'];
		}
		// 在该店铺使用的所有优惠券
		$coupons = db('coupons')->alias('c')->join('user u','c.cp_user_id=u.id')->field('c.*,u.nick_name')->where($map)->select();

		$this->assign('coupons',$coupons);
		return $this->fetch('coupons/coupList');
	}

	/**
     * 优惠券详情
     */
	public function coupDetail(){
		$id = input('get.id');
		$coupon = db('coupons')->alias('c')->join('user u','c.cp_user_id=u.id')->field('c.*,u.nick_name')->where('c.cp_id='.$id)->find();

		$this->assign('coupon',$coupon);
		return $this->fetch('coupons/coupDetail');
	}
}